{template 'common/header'}
<script>
    $(function(){
        $(".add").on('click',function(){
            var name = $("#name").val();
            var phone = $("#phone").val();
            var price = $("#price").val();
            var remark = $("#remark").val();
            var code = $("#code").val();
            var url = "{php echo $this->createWebUrl('express',array('op' => 'company_add'))}";
            $.ajax({
                type : 'post',
                url : url,
                data : {'name' : name, 'phone' : phone, 'price' : price, 'remark' : remark,'code' : code},
                success : function(data){
                    if(data == 111){
                        location.reload();
                    }else{
                        alert(data);
                    }
                }
            });
        });
        $(".del").on('click',function(){
            if(confirm("是否确定删除该快递公司")){
                var id = $(this).parent().parent().attr('company_id');
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_del'))}";
                $.ajax({
                  type : 'post',
                  url : url,
                  data : {'id' : id},
                  success : function(data){
                      if(data == 111){
                        location.reload();
                      }else{
                          alert(data);
                      }
                  }
                });
            }
        });
        $(".name").on('blur',function(){
            var name = $(this).val();
            if(name){
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_update'))}";
                var company_id = $(this).parent().parent().attr('company_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'company_id' : company_id, 'name' : name},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }
                    }
                });
            }else{
                alert("名称不能为空！");
            }
        });
        $(".phone").on('blur',function(){
            var phone = $(this).val();
            if(phone == ''){
                phone = ' ';
            }
            if(phone){
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_update'))}";
                var company_id = $(this).parent().parent().attr('company_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'company_id' : company_id, 'phone' : phone},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }
                    }
                });
            }
        });
        $(".price").on('blur',function(){
            var price = $(this).val();
            if(price == ''){
                price = '';
            }
            if(price){
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_update'))}";
                var company_id = $(this).parent().parent().attr('company_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'company_id' : company_id, 'price' : price},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }
                    }
                });
            }
        });
        $(".code").on('blur',function(){
            var code = $(this).val();
            if(code == ''){
                code = ' ';
            }
            if(code){
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_update'))}";
                var company_id = $(this).parent().parent().attr('company_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'company_id' : company_id, 'code' : code},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }
                    }
                });
            }
        });
        $(".advance").on('blur',function(){
            var advance = $(this).val();
            if(advance == ''){
                advance = ' ';
            }
            if(advance){
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_update'))}";
                var company_id = $(this).parent().parent().attr('company_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'company_id' : company_id, 'advance' : advance},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }
                    }
                });
            }
        });
        $(".remark").on('blur',function(){
            var remark = $(this).val();
            if(remark == ''){
                remark = ' ';
            }
            if(remark){
                var url = "{php echo $this->createWebUrl('express',array('op' => 'company_update'))}";
                var company_id = $(this).parent().parent().attr('company_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'company_id' : company_id, 'remark' : remark},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }
                    }
                });
            }
        });
    });
</script>
<ul class="nav nav-tabs">
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'order_list'))}">快递订单</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'add'))}">添加订单</a></li>
    <li class="active"><a href="{php echo $this->createWebUrl('express', array('op'=>'company'))}">快递公司管理</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'server'))}">服务社管理</a></li>
</ul>
<div>
    <div class="panel panel-primary">
        <div class="panel-heading">
            <div class="panel-title">
                添加快递公司
            </div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-2">
                    <input type="text" class="form-control" placeholder="快递名称" id="name"/>
                </div>
                <div class="col-xs-2">
                    <input type="text" class="form-control" placeholder="电话" id="phone" />
                </div>
                <div class="col-xs-2">
                    <input type="text" class="form-control" placeholder="默认单价" id="price" />
                </div>
                <div class="col-xs-2">
                    <input type="text" class="form-control" placeholder="编码" id="code" />
                </div>
                <div class="col-xs-2">
                    <input type="text" class="form-control" placeholder="备注" id="remark" />
                </div>
                <div class="col-xs-2">
                    <button class="btn btn-primary add">添加</button>
                </div>
            </div>
        </div>
    </div>
    <div>
        <table class="table">
            <tr>
                <th>快递公司</th>
                <th>电话</th>
                <th>默认单价</th>
                <th>默认已收款</th>
                <th>编码</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
            {loop $companys $company}
            <tr company_id="{$company['id']}">
                <td>
                    <input type="text" value="{$company['name']}" class="form-control name"/>
                </td>
                <td>
                    <input type="text" value="{$company['phone']}" class="form-control phone"/>
                </td>
                <td>
                    <input type="text" value="{$company['price']}" class="form-control price"/>
                </td>
                <td>
                    <input type="text" value="{$company['advance']}" class="form-control advance"/>
                </td>
                <td>
                    <input type="text" value="{$company['code']}" class="form-control code" />
                </td>
                <td>
                    <input type="text" value="{$company['remark']}" class="form-control remark"/>
                </td>
                <td>
                    <button class="btn btn-danger del" >删除</button>
                </td>
            </tr>
            {/loop}
        </table>
    </div>
</div>




{template 'common/footer'}